package com.lune.job.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lune.job.mapper.CompanyMapper;
import com.lune.job.mapper.UserMapper;
import com.lune.job.pojo.Company;
import com.lune.job.pojo.ResPageBean;
import com.lune.job.pojo.User;
import com.lune.job.service.ICompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Caiyilin
 * @since 2022-03-06
 */
@Service
public class CompanyServiceImpl extends ServiceImpl<CompanyMapper, Company> implements ICompanyService {

    @Autowired
    private CompanyMapper companyMapper;

    /**
     * 登录方法
     * @param account
     * @param password
     * @return
     */
    @Override
    public Company login(String account, String password) {
        Company param = new Company();
        param.setAccount(account);
        param.setPassword(password);
        List<Company> list = companyMapper.query(param);
        if (list!=null && list.size()>0){
            return  list.get(0);
        }else {
            return  null;
        }

    }

    /**
     * 部分修改单位
     * @param company
     * @return
     */
    @Override
    public int updateSelective(Company company) {
        return companyMapper.updateSelective(company);
    }

    /**
     * 分页查询单位
     * @param currentPage
     * @param size
     * @param company
     * @return
     */
    @Override
    public ResPageBean getAllCompanyByPage(Integer currentPage, Integer size, Company company) {
        Page<Company> page = new Page<>(currentPage, size);
        IPage<Company> companyIPage = companyMapper.getAllCompanyByPage(page,company);
        ResPageBean resPageBean = new ResPageBean(companyIPage.getTotal(), companyIPage.getPages(), companyIPage.getRecords());
        return  resPageBean;
    }

    /**
     * 条件查询单位
     * @param company
     * @return
     */
    @Override
    public List<Company> queryByCon(Company company) {
        return companyMapper.queryByCon(company);
    }
}
